﻿<%@ Page Language="C#" MasterPageFile="~/Theme/Stander/Stander.master" AutoEventWireup="true" CodeFile="MediaOrders.aspx.cs" Inherits="Bill_MediaOrders" Title="Untitled Page" %>
<%@ Register Src="../User Controls/OrderStateControl.ascx" TagName="OrderStateControl"
    TagPrefix="uc2" %>
<%@ Register Src="../User Controls/CampaignPeriodControl.ascx" 
    TagName="CampaignPeriodControl" TagPrefix="uc1" %>
<%@ Import Namespace="Active.Core" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<uc2:OrderStateControl id="OrderStateControl1" runat="server"></uc2:OrderStateControl>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="MainView" runat="server">
<ActiveWeb:MediaBill ID="mediaBill" Visible="false" runat="server" />
<asp:Repeater ID="MediaOrdersRepeater" runat="server" DataSourceID="MediaOrdersDataSource" 
    OnItemCommand="MediaOrdersRepeater_ItemCommand" OnItemDataBound="MediaOrdersRepeater_ItemDataBound">
<HeaderTemplate>
<h2>媒介订单列表</h2>
<table cellpadding="0" cellspacing="0" class="normal mouseOver">
    <tr>
        <th rowspan="2">&nbsp;</th>
        <%if (GetOrder().Media.Category == MediaType.TV)
          { %>
        <th rowspan="2">频道</th>
        <th rowspan="2">时段</th>
        <%} %>
        <th rowspan="2">位置</th>
        <th rowspan="2" >单价</th>
        <th rowspan="2">规格</th>
        <%= MonthsHeader %>
        <th rowspan="2">次数</th>
        <th rowspan="2">优惠率</th>
        <th rowspan="2">实付</th>
        <th rowspan="2">&nbsp;</th>
    </tr>
    <tr>
    <%=DaysHeader %>
    </tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
    <td><asp:LinkButton ID="EditLinkButton" Enabled='<%# CanEdit() %>' 
        CommandName="Edit" CommandArgument='<%# Eval("Id") %>'
         runat="server">编</asp:LinkButton></td>
    <%if (GetOrder().Media.Category == MediaType.TV)
      { %>
    <td><%# Eval("Channel") %></td>
    <td><%# Eval("TimeSlot") %></td>
    <%} %>
    <td><%# Eval("Position")%></td>
    <td class="right"><%# Formater.FormatPrice((decimal)Eval("UnitPrice"), (Active.Core.OrderType)Eval("Category")) %></td>
    <td><%# Eval("Duration")%></td>
    <%# FormatCampaignPeriodHTML((string)Eval("CampaignPeriod"))%>
    <td class="right"><%# Eval("Times")%></td>
    <td class="right"><%# Eval("Discount", "{0:p2}") %></td>
    <td class="right"><%# Formater.FormatMoney(Eval("Payout"))%></td>
    <td><asp:LinkButton ID="DeleteLinkButton" Enabled='<%# CanEdit() %>' 
        CommandName="Delete" CommandArgument='<%# Eval("Id") %>' 
         runat="server" OnClientClick="return deleteConfirm(event);">删</asp:LinkButton></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr id="TotalCaculateFooter" runat="server">
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
<csla:CslaDataSource ID="MediaOrdersDataSource" runat="server" 
    TypeName="Active.Core.MediaOrders, Active.Core"
    TypeSupportsPaging="False" TypeSupportsSorting="False" 
    OnSelectObject="MediaOrdersDataSource_SelectObject">
</csla:CslaDataSource>
<p><asp:LinkButton ID="lbtnAddMediaOrder" runat="server" 
    OnClick="lbtnAddMediaOrder_Click">添加媒介订单</asp:LinkButton></p>
<asp:Panel ID="plMediaDescription" runat="server">
<h2>订单备注</h2>
<p>
<asp:TextBox ID="txtOrderMediaDescription" TextMode="MultiLine" 
    Width="95%" Rows="12" runat="server"></asp:TextBox>
</p>
</asp:Panel>
<asp:PlaceHolder ID="phOperations" runat="server">
<h2>确认操作</h2>
<p>
<span class="name">当前媒介剩余预付款:</span>
<span class="value"><%= Formater.FormatMoney(GetOrder().Media.Advance) %> ,</span>
<span class="name">已从媒介剩余预付款中支付:</span>
<span class="value"><%= Formater.FormatMoney(GetOrder().DeductFromAdvance) %></span>
</p>
<p>
<span class="name">当前媒介剩余返点:</span>
<span class="value"><%= Formater.FormatMoney(GetOrder().Media.Brokerage) %> ,</span>
<span class="name">已从媒介剩余返点中支付:</span>
<span class="value"><%= Formater.FormatMoney(GetOrder().DeductFromBrokerage) %></span>
</p>
    <asp:PlaceHolder ID="phSubmitBill" runat="server">
        <p>
        <asp:Button ID="btnClearPay" runat="server" Text="清除已支付款" 
            OnClick="btnClearPay_Click"
            OnClientClick="return confirm('确定要清除吗?')" />
        </p>
        <asp:PlaceHolder ID="phSubmitPayInfo" runat="server">
        <p>
        <span class="name">从预付款中支付给媒介:</span>
        <span class="value">
            <asp:TextBox ID="txtDeductFromAdvance" runat="server"></asp:TextBox> , </span>
        <span class="name">从返点中支付给媒介:</span>
        <span class="value">
            <asp:TextBox ID="txtDeductFromBrokerage" runat="server"></asp:TextBox></span>
        </p>
        <p>
        <asp:Button ID="btnSubmitPayInfo" runat="server" Text="确定支付" 
            OnClick="btnSubmitPayInfo_Click"
            OnClientClick="return confirm('确定要支付吗?')" />
        </p>
        </asp:PlaceHolder>
        <p><asp:Button ID="btnSubmitBill" runat="server" Text="提 交" 
            OnClientClick="return confirm('确定要提交吗?')" OnClick="btnSubmitBill_Click" /></p>
    </asp:PlaceHolder>
<p><asp:Button ID="btnCancelConfirmBill" runat="server" Text="退 回" OnClientClick="return confirm('确定要退回吗?')" OnClick="btnCancelConfirmBill_Click" /></p>
</asp:PlaceHolder>
</asp:View>
<asp:View ID="EditMediaOrderView" runat="server">
<p><asp:LinkButton ID="lbtnReturn" runat="server" OnClick="lbtnReturn_Click">返 回</asp:LinkButton></p>
<h2>请选择对应的客户订单</h2>
<asp:Repeater ID="CustomerOrdersRepeater" runat="server" DataSourceID="CustomerOrdersDataSource" 
    OnItemCommand="CustomerOrdersRepeater_ItemCommand" OnItemDataBound="CustomerOrdersRepeater_ItemDataBound">
<HeaderTemplate>
<table cellpadding="0" cellspacing="0" class="normal mouseOver">
    <tr>
        <th>&nbsp;</th>
        <th>订单类型</th>
        <%if (GetOrder().Media.Category == MediaType.TV)
          { %>
        <th>频道</th>
        <%} %>
        <th>单价</th>
        <th>次数</th>
        <th>优惠率</th>
        <th>实收</th>
    </tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
    <td><asp:LinkButton ID="SelectLinkButton" 
        CommandName="Select" CommandArgument='<%# Eval("Id") %>'
         runat="server">选择</asp:LinkButton>
    </td>
    <td>
        <%# Formater.Translate(Eval("Category").ToString()) %>
    </td>
    <%if (GetOrder().Media.Category == MediaType.TV)
      { %>
    <td><%# Eval("Channel") %></td>
    <%} %>
    <td class="right"><%# Formater.FormatMoney((decimal)Eval("UnitPrice")) %></td>
    <td class="right"><%# Eval("Times")%></td>
    <td class="right"><%# Eval("RealDiscount", "{0:p2}")%></td>
    <td class="right"><%# Formater.FormatMoney((decimal)Eval("RealPayout")) %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<csla:CslaDataSource ID="CustomerOrdersDataSource" runat="server" 
    TypeName="Active.Core.CustomerOrders, Active.Core"
    TypeSupportsPaging="False" TypeSupportsSorting="False" 
    OnSelectObject="CustomerOrdersDataSource_SelectObject">
</csla:CslaDataSource>
<asp:Panel ID="plEditMediaOrderForm" runat="server" Visible="false">
<h2>填写媒介订单</h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DetailsView ID="MediaOrderDetailsView" runat="server" DataSourceID="MediaOrderDataSource"
    AutoGenerateRows="False"
    OnItemCommand="MediaOrderDetailsView_ItemCommand" 
    OnDataBound="MediaOrderDetailsView_DataBound" DataKeyNames="Id">
<Fields>
    <asp:TemplateField HeaderText="订单类型:">
        <InsertItemTemplate>
            <asp:DropDownList ID="ddlOrderType" runat="server" SelectedValue='<%# Bind("Category") %>'>
                <asp:ListItem Text="输入单价" Value="Pay"></asp:ListItem>
                <asp:ListItem Text="套播" Value="Series"></asp:ListItem>
                <asp:ListItem Text="赠送" Value="Present"></asp:ListItem>
                <asp:ListItem Text="追加款" Value="Additional"></asp:ListItem>
            </asp:DropDownList>
        </InsertItemTemplate>
        <EditItemTemplate>
            <asp:DropDownList ID="ddlOrderType" runat="server" SelectedValue='<%# Bind("Category") %>'>
                <asp:ListItem Text="输入单价" Value="Pay"></asp:ListItem>
                <asp:ListItem Text="套播" Value="Series"></asp:ListItem>
                <asp:ListItem Text="赠送" Value="Present"></asp:ListItem>
                <asp:ListItem Text="追加款" Value="Additional"></asp:ListItem>
            </asp:DropDownList>
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="频道:" >
        <InsertItemTemplate>
            <asp:DropDownList ID="ddlChannels" DataSource='<%# GetOrder().Media.ChannelsArray %>' 
                runat="server" SelectedValue='<%# Bind("Channel") %>'>
            </asp:DropDownList>
        </InsertItemTemplate>
        <EditItemTemplate>
            <asp:DropDownList ID="ddlChannels" DataSource='<%# GetOrder().Media.ChannelsArray %>' 
                runat="server" SelectedValue='<%# Bind("Channel") %>'>
            </asp:DropDownList>
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="时段:">
        <InsertItemTemplate>
            <asp:TextBox ID="txtTimeSlot" Text='<%# Bind("TimeSlot") %>' runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtenderTimeSlot" 
             TargetControlID="txtTimeSlot" ServiceMethod="GetUsedTimeSlots"
             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
             CompletionInterval="500" EnableCaching="true" Enabled="true"
             CompletionSetCount="10"/>
        </InsertItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtTimeSlot" Text='<%# Bind("TimeSlot") %>' runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtenderTimeSlot" 
             TargetControlID="txtTimeSlot" ServiceMethod="GetUsedTimeSlots"
             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
             CompletionInterval="500" EnableCaching="true" Enabled="true"
             CompletionSetCount="10"/>
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="位置:">
        <EditItemTemplate>
            <asp:TextBox ID="txtPosition" runat="server" Text='<%# Bind("Position") %>'></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender2" 
             TargetControlID="txtPosition" ServiceMethod="GetUsedPositions"
             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
             CompletionInterval="500" EnableCaching="true" Enabled="true"
             CompletionSetCount="10"/>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:TextBox ID="txtPosition" runat="server" Text='<%# Bind("Position") %>'></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender3" 
             TargetControlID="txtPosition" ServiceMethod="GetUsedPositions"
             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
             CompletionInterval="500" EnableCaching="true" Enabled="true"
             CompletionSetCount="10"/>
        </InsertItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="规格:">
        <InsertItemTemplate>
            <asp:TextBox ID="txtDuration" Text='<%# Bind("Duration") %>' runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtenderDuration" 
             TargetControlID="txtDuration" ServiceMethod="GetUsedDurations"
             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
             CompletionInterval="500" EnableCaching="true" Enabled="true"
             CompletionSetCount="10"/>
        </InsertItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtDuration" Text='<%# Bind("Duration") %>' runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtenderDuration" 
             TargetControlID="txtDuration" ServiceMethod="GetUsedDurations"
             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
             CompletionInterval="500" EnableCaching="true" Enabled="true"
             CompletionSetCount="10"/>
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="广告周期:">
        <InsertItemTemplate>
        <uc1:CampaignPeriodControl ID="CampaignPeriodControl1" 
            CampaignPeriodString='<%# Bind("CampaignPeriod") %>'
            runat="server" />
        </InsertItemTemplate>
        <EditItemTemplate>
        <uc1:CampaignPeriodControl ID="CampaignPeriodControl1"
            runat="server" />
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="单价:">
        <InsertItemTemplate>
            <asp:TextBox ID="txtUnitPrice" Text='<%# Bind("UnitPrice") %>'
                CssClass="short" runat="server">0</asp:TextBox>
        </InsertItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtUnitPrice" Text='<%# Bind("UnitPrice", "{0:f2}") %>'
                CssClass="short" runat="server">0</asp:TextBox>
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="优惠率:">
        <InsertItemTemplate>
            <asp:TextBox ID="txtDiscount" Text='<%# Bind("Discount", "{0:p2}") %>' 
                CssClass="short" runat="server">0</asp:TextBox>%
        </InsertItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtDiscount" Text='<%# Bind("Discount", "{0:p2}") %>' 
                CssClass="short" runat="server">0</asp:TextBox>%
        </EditItemTemplate>
    </asp:TemplateField>
    <asp:CommandField ShowInsertButton="True" ShowEditButton="True" InsertText="添加"
        EditText="更新" CancelText="返 回" ButtonType="Button" />
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
<csla:CslaDataSource ID="MediaOrderDataSource" runat="server" 
    TypeName="Active.Core.MediaOrder, Active.Core"
    TypeSupportsPaging="False" TypeSupportsSorting="False" 
    OnSelectObject="MediaOrderDataSource_SelectObject" 
    OnInsertObject="MediaOrderDataSource_InsertObject" 
    OnUpdateObject="MediaOrderDataSource_UpdateObject">
</csla:CslaDataSource>
</asp:Panel>
</asp:View>
</asp:MultiView>
</asp:Content>

